home *** CD-ROM | disk | FTP | other *** search
- /* LAP802Mdev.c contains the code for mdev resource
-
- (c) Copyright 1990-91 by Apple Computer, Inc. All rights reserved.
-
- */
-
- /*
- 1.2 Oct 1990 Rajesh written for IEEE 802.3 LAP.
- It contains routines to implement 'mdev' resource.
- */
-
- #include <Slots.h>
- #include <SysEqu.h>
- #include <StdIO.h>
- #include <ToolUtils.h>
- #include <Memory.h>
- #include <Packages.h>
- #include <Resources.h>
- #include <ROMDefs.h>
-
- #define LOWBYTE 0x0F
- #define ZERO '0'
- #define OFFSET 40
- #define STR_RES_ID -4032
- #define spDrvrSWMask 0x02 /* mask off driver software field */
- #define spDrvrHWMask 0x01 /* mask off driver hardware field */
-
- void addSlotInName(title, displayNo);
-
- mdevStart()
- {
- OSErr rc = -1;
- struct SpBlock sb;
- char title[255]; /* name to be displayed for LAP icon */
- StringHandle strHdl; /* for the LAP name, 'STR ' resource */
- long prevSlotNo=0; /* slot no. which is used for successive call */
- long currentSlotNo=0; /* slot no. for the current card */
- short noOfCards=0; /* used to decide whether to display a slot no */
- short displayNo; /* the slot number to be displayed with the name */
- short nameLen; /* length of the string to be displayed */
-
- prevSlotNo = GetD2(); /* start search from the next card */ /* + 1; RAJESH JUNE 4, 1991 */
-
- bzero((char *)&sb, sizeof(sb));
- sb.spSlot = 0; /* 1; RAJESH JUNE 4, 1991 */
- sb.spCategory = catNetwork;
- sb.spCType = typeEtherNet;
- sb.spTBMask = spDrvrSWMask | spDrvrHWMask;
- /* first find out how many ethernet cards are there */
- while (SNextTypeSRsrc(&sb) == noErr)
- noOfCards++;
-
- bzero((char *)title, sizeof(title));
-
- bzero((char *)&sb, sizeof(sb));
- sb.spSlot = prevSlotNo;
- sb.spCategory = catNetwork;
- sb.spCType = typeEtherNet;
- sb.spTBMask = spDrvrSWMask | spDrvrHWMask;
- rc = SNextTypeSRsrc(&sb);
- if (rc == noErr) {
- currentSlotNo = sb.spSlot;
- prevSlotNo = currentSlotNo;
- strHdl = GetString(STR_RES_ID);
- if (strHdl != nil) {
- HLock(strHdl);
- nameLen = *(*strHdl);
- BlockMove(*strHdl,title,nameLen+1);
- HUnlock(strHdl);
- if (noOfCards > 1) { /* more than 1 card, display slot number */
- /* convert 09-0E to 1-6 range */
- displayNo = (currentSlotNo + OFFSET) & LOWBYTE;
- nameLen++;
- addSlotInName(title, displayNo, &nameLen);
- }
- else;
- *title = nameLen;
- }
- else {
- rc = ResError();
- }
- SetA0(title); /* Refer to MacTCP LAP Tech Note */
- SetD1(currentSlotNo); /* This is the format required by CPanel.a */
- SetD2(++prevSlotNo);
- }
- SetD0((long) rc); /* return status in d0 */
- }
-
- void addSlotInName(title, displayNo, nameLen)
- char *title;
- short displayNo;
- short *nameLen;
- {
- short remainder;
-
- *(title + (*nameLen)++) = ' ';
- *(title + (*nameLen)++) = '(';
- if (displayNo >= 100) {
- remainder = displayNo % 100;
- *(title + (*nameLen)++) = (displayNo / 100) + ZERO;
- *(title + (*nameLen)++) = (remainder / 10) + ZERO;
- *(title + (*nameLen)++) = (remainder % 10) + ZERO;
- }
- else {
- if (displayNo >= 10) {
- *(title + (*nameLen)++) = (displayNo / 10) + ZERO;
- *(title + (*nameLen)++) = (displayNo % 10) + ZERO;
- }
- else
- *(title + (*nameLen)++) = displayNo + ZERO;
- }
- *(title + (*nameLen)) = ')';
- *title = *nameLen;
- }
-